package cn.edu.scau.cmi.luodongmei.gui;

import cn.edu.scau.cmi.luodongmei.singleton.Marshals;
import javafx.geometry.Pos;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;

public class MultipletonGUI extends Pane {
	public MultipletonGUI() {
		BorderPane pane = new BorderPane();
		pane.setPrefSize(500, 300);


		Text text = new Text("创建元帅个数：10");
		// 获得Marshals对象实例
		Marshals marshals1 = Marshals.getRandomInstance();
		//System.out.println("创建元帅个数："+marshals1.getNo());
		Text text1 = new Text("元帅1:[" + marshals1.getNo() + "]");
		// 再次获得Multipleton对象实例
		Marshals marshals2 = Marshals.getRandomInstance();
		//System.out.println("元帅2:[" + marshals2.getNo() + "]");
		Text text2 = new Text("元帅2:[" + marshals2.getNo() + "]");
		// 比较两个对象是否是同一个对象实例
		Text text3 = new Text();
		if (marshals1 == marshals2) {
			//System.out.println("这是同一个元帅！");
			text3.setText("这是同一个元帅！");
		} else {
			//System.out.println("这是不同的元帅！");
			text3.setText("这是不同的元帅！");
		}

		//text.setFont(Font.font("Verdana", 20));

		VBox box = new VBox();
		box.getChildren().addAll(text,text1,text2,text3);
		box.setSpacing(20);
		box.setAlignment(Pos.CENTER);
		pane.setCenter(box);

		getChildren().add(pane);

	}
}
